/**
 *
 * @author TQNINH
 */
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class DoctorManager {
    HashMap<String, Doctor> DoctorHashMap = new HashMap<String, Doctor>();
    
    public DoctorManager() {
        
    }
    public void add() {
        Doctor objD = new Doctor();
        Scanner input = new Scanner(System.in);
        System.out.print("Code: ");
        objD.setCode(input.next());
        System.out.print("Name: ");
        objD.setName(input.next());
        System.out.print("Specialization: ");
        objD.setSpec(input.next());
        while(true) {
            try {
                System.out.print("Hours: ");
                objD.setHour(input.nextInt());
                break;
            } catch(Exception ex) {
                System.out.println("Must be a digit.....");
            }
        }
        DoctorHashMap.put(objD.getCode(), objD);
    }
    
    public void search() {
        Scanner input = new Scanner(System.in);
        System.out.print("Input code of Doctor to search: ");
        Doctor objD = DoctorHashMap.get(input.next());
        if(objD != null ) {
            System.out.println(objD.toString());
        } else {
            System.out.println("Code not found....");
        }
    }
    
    public void display() {
        System.out.println("The list has total: " + DoctorHashMap.size() + " doctor");
//        Set s = DoctorHashMap.keySet();
//        Iterator i = s.iterator();
//        while(i.hasNext()) {
//            System.out.println(DoctorHashMap.get(i.next()).toString());
//        }
        Set s = DoctorHashMap.entrySet();
        Iterator i = s.iterator();
        while(i.hasNext()) {
            Map.Entry me = (Map.Entry)i.next();
            System.out.println(me.getValue());
        }
    }
    
    public static void main(String[] args) {
        int choose = 0;
        Scanner sc = new Scanner(System.in);
        DoctorManager objDoctor = new DoctorManager();
        
        while(true) {
            System.out.println("\n\nLIFELINE HOSPITAL");
            System.out.println("1. Register a doctor ");
            System.out.println("2. Search and Display a doctor");
            System.out.println("3. Publish the entire list");
            System.out.println("4. Exit");
            
            while(true) {
                try {
                    System.out.print("Enter your choose: ");
                    choose = sc.nextInt();
                    break;
                } catch(Exception ex) {
                    System.out.println("Must be a digit.....");
                }
            }
            
            switch (choose) {
                case 1:
                    objDoctor.add();
                    break;
                case 2:
                    objDoctor.search();
                    break;
                case 3:
                    objDoctor.display();
                    break;
                case 4:
                    System.out.println("Program Exit Successfully: ");
                    System.exit(0);
                default:
                    System.out.println("Wrong choosen, choose again....");
                    break;
            }
        }
    }
}
